using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DotNetCoreStudy.Page.services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace DotNetCoreStudy.Page.Pages.Employee
{
    public class AddEmployeeModel : PageModel
    {
        [BindProperty]
        public Models.Employee employee { get; set; }

        public readonly IEmployeeService _employeeService;

        public AddEmployeeModel(IEmployeeService departmentService)
        {
            _employeeService = departmentService;
        }

        public async Task<IActionResult> OnPostAsync(int departmentId)
        {
            employee.DepartmentId = departmentId;
            if (!ModelState.IsValid)
            {
                return Page();
            }
            await _employeeService.Add(employee);
            return RedirectToPage("EmployeeList",routeValues:new { departmentId});
        }
    }
}
